package com.example.administrator.daydayappmarket.game.fragment.fragments.classify.fragment.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.daydayappmarket.Contacts;
import com.example.administrator.daydayappmarket.R;
import com.example.administrator.daydayappmarket.game.fragment.fragments.classify.fragment.model.GameClassifyGridViewInfo;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by 郎志奇 on 2016/12/28.
 */

public class GameClassifyGridViewAdapter extends BaseAdapter {

    private List<GameClassifyGridViewInfo> data;

    private Context context;

    public GameClassifyGridViewAdapter(List<GameClassifyGridViewInfo> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public GameClassifyGridViewInfo getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {

        ViewHolder holder=null;

        if (convertView == null) {

            convertView = LayoutInflater.from(context).inflate(R.layout.item_game_classify_gridview, parent, false);
            holder=new ViewHolder(convertView);

            convertView.setTag(holder);

        }else {

            holder= (ViewHolder) convertView.getTag();
        }

        //设置数据

        holder.mItemGameClassifyGridViewText.setText(
                data.get(i).getTitle()
        );

        Picasso.with(context).load(Contacts.IMAGE_PREFIX+data.get(i).getImage())
                .into(holder.mItemGameClassifyGridViewImage);


        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.item_game_classify_gridView_image)
        ImageView mItemGameClassifyGridViewImage;
        @InjectView(R.id.item_game_classify_gridView_text)
        TextView mItemGameClassifyGridViewText;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
